package cn.example.gate.netty.session;

import io.netty.channel.Channel;
import org.artifact.core.context.packet.IPacket;
import org.artifact.core.context.session.ISession;
import org.artifact.core.lang.IServer;
import org.artifact.core.plugin.dispatcher.DispatcherPlugin;

import java.net.SocketAddress;

public class NettySession extends ISession {

	private Channel channel;
	
	public NettySession(Channel channel) {
		super();
		this.channel = channel;
	}

	@Override
	public String getId() {
		return null;
	}

	@Override
	public SocketAddress localAddress() {
		return null;
	}

	@Override
	public SocketAddress remoteAddress() {
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> T getChannel() {
		return (T) channel;
	}

	@Override
	public void setChannel(Object channel) {

	}

	@Override
	public void close() {

	}

	@Override
	public boolean isOpen() {
		return channel.isOpen();
	}

	@Override
	public boolean isActive() {
		return channel.isActive();
	}

	@Override
	public boolean isWritable() {
		return channel.isWritable();
	}

	@Override
	protected void writeAndFlush(IPacket packet) {
		channel.writeAndFlush(packet);
	}

	@Override
	public void receivePacket(IPacket packet) {
		DispatcherPlugin plugin = IServer.me().getPlugins().getIPlugin(DispatcherPlugin.class);
		plugin.disp(this,packet);
	}

}
